package em;

import java.util.LinkedList;
import java.util.List;

/**
 * Holds data for each iteration in EM algorithm
 */
public class Logger {

	/**
	 * Holds data to log after each iteration
	 */
	private class LogData {
		private double logLikelihood;
		private double meanPerplexity;
	}
	
	private List<LogData> itersData; // holds data for each iteration
	
	/**
	 * Constructor- creates a new Logger object
	 */
	public Logger() {
		itersData = new LinkedList<LogData>();
	}
	
	/**
	 * Logs data for new iteration
	 * @param logLikelihood log on likelihood after current iteration
	 * @param meanPerplexity value of mean perplexity after current iteration
	 */
	public void logNewIter(double logLikelihood, double meanPerplexity) {
		
		// initialize a new data element for current iteration
		LogData data = new LogData();
		data.logLikelihood = logLikelihood;
		data.meanPerplexity = meanPerplexity;
		
		// log the data for current iteration
		itersData.add(data);
	}
	
	/**
	 * Returns log on likelihood of indicated iteration
	 * @param iterIndex number of iteration to check
	 * @return log on likelihood of indicated iteration
	 */
	public double getIterLogLikelihood(int iterIndex) {
		return itersData.get(iterIndex).logLikelihood;
	}
	
	/**
	 * Returns value of mean perplexity of indicate iteration
	 * @param iterInex number of iteration to check
	 * @return value of mean perplexity of indicate iteration
	 */
	public double getIterMeanPerplexity(int iterInex) {
		return itersData.get(iterInex).meanPerplexity;
	}
}
